package com.example.demo_news.controller.user;

import java.util.List;

import com.example.demo_news.entity.OfficialAccount;
import com.example.demo_news.service.User.UserIndexService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
public class IndexController {

    @Autowired
    private UserIndexService userIndexService;
    // 跳转到首页
    @RequestMapping("/index")
    public String indexController(Model model) {
        userIndexService.subscribeNews(model);
        return "/user/index";
    }

    // 我的关注,服务页
    @RequestMapping("/services")
    public String service(Model model) {
        List<OfficialAccount>officialAccounts=userIndexService.findLikeOfficialAccount();
        model.addAttribute("officialAccounts", officialAccounts);

        List<OfficialAccount>allOfficialAccounts=userIndexService.findAll();
        model.addAttribute("allOfficialAccounts", allOfficialAccounts);
        return "/user/services";
    }
      ///添加关注
      @RequestMapping("/likeService")
      public String likeService(Integer id){
          userIndexService.likeService(id);
          return "/user/services";
      }
        //跳转到分类页,朝闻天下
    @RequestMapping("/portfolio")
    public String portfolio(Model model){
        userIndexService.findAllNews(model);
        return "/user/portfolio";
    }

}
